const initTable = function(translate) {
  this.setTableSize(translate);
  window.addEventListener('resize', () => {
    this.tableTimer && clearTimeout(this.tableTimer)
    this.tableTimer = setTimeout(() => this.setTableSize(translate), 100)
  })
}

const setTableSize = function(translate = 0) {
  let target = document.querySelector('.container-content')
  if (!target) return
  let pager = document.querySelector('.pager')
  let pagerTitle = document.querySelector('.order-title-total')
  let height = target.offsetHeight - 65 - translate - 2
  if (pager) height -= pager.offsetHeight
  if (pagerTitle) height -= pagerTitle.offsetHeight
  this.options.tableHeight = height
}

const backTableTop = function() {
  let list = document.querySelectorAll('.ivu-table-body')
  if (list) {
    [...list].forEach(target => {
      target.scrollTop = 0
    })
  }
}


export default {
  initTable,
  setTableSize,
  backTableTop
}